package com.jk.vehicle.mini.service.impl;

import com.jk.vehicle.mini.dao.CorpMapper;
import com.jk.vehicle.mini.entity.Corp;
import com.jk.vehicle.mini.service.CorpService;
import com.jk.vehicle.core.service.impl.AbstractService;
import com.jk.vehicle.mini.util.QueryUtil;
import com.jk.vehicle.mini.util.SequenceUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.EntityColumn;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.mapperhelper.EntityHelper;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * This is Description for CorpServiceImpl
 *
 * @author Administrator
 * @date 2021/02/08
 */
@Service
public class CorpServiceImpl extends AbstractService<Corp> implements CorpService {
    /**
	 * 注入CorpMapper
	 */
    @Resource
    private CorpMapper corpMapper;

    /**
    * 根据查询条件查询单表数据
    * @param paramMap 查询条件
    * @return 查询结果
    */
    public List<Corp> queryByParams(Map<String, Object> paramMap){
        Condition condition = new Condition(Corp.class);
        Example.Criteria criteria = condition.createCriteria();
        Map<String, EntityColumn> propertyMap = EntityHelper.getEntityTable(Corp.class).getPropertyMap();
        QueryUtil.spliceQueryParam(criteria, paramMap,  propertyMap, condition);
        return corpMapper.selectByCondition(condition);
    }

    /**
     * 根据厂家id从master数据源查询对应数据源
     * @param id
     * @return
     */
    @Override
    public String selectDsNameById(Long id) {
        return corpMapper.selectDsNameById(id);
    }

    /**
     * 查询所有通用厂家对应数据源列表
     * @return
     */
    @Override
    public List<String> selectCommonCorpDsNameList() {
        return corpMapper.selectCommonCorpDsNameList();
    }

    /**
     * 查询所有厂家对应数据源列表
     * @return
     */
    @Override
    public List<String> selectAllCorpDsNameList() {
        return corpMapper.selectAllCorpDsNameList();
    }

    @Override
    public void save(Corp corp, String dsName) {
        corp.setId(SequenceUtils.nextId());
        corp.setCreateDate(new Date());
        super.save(corp, dsName);
    }

    @Override
    public void update(Corp corp, String dsName){
        corp.setUpdateDate(new Date());
        super.update(corp, dsName);
    }
}
